$(function(){
    $('.thumb').each(function(i,obj){
        var boxW=$(obj).width(),boxH=$(obj).height();
        var boxB=boxW/boxH;
        var img=$(obj).children('img');
        var imgW=img.width(),imgH=img.height();
        var imgB=imgW/imgH;
        if(boxB>imgB){console.log(1);
            img.css({width:'auto',height:'100%',display:'inline-block'});
        }else if(boxB<imgB){console.log(2);
            img.css({width:'100%',height:'auto',display:'inline-block',verticalAlign:'middle'});
        }
    });
    $(window).scroll(function(){
        $('.thumb').each(function(i,obj){
            var boxW=$(obj).width(),boxH=$(obj).height();
            var boxB=boxW/boxH;
            var img=$(obj).children('img');
            var imgW=img.width(),imgH=img.height();
            var imgB=imgW/imgH;
            if(boxB>imgB){
                img.css({width:'auto',height:'100%',display:'inline-block'});
            }else if(boxB<imgB){
                img.css({width:'100%',height:'auto',display:'inline-block',verticalAlign:'middle'});
            }
        });
    });
    $('.zuopin_list').delegate('.thumb','click',function(){
        var img=$(this).children('img');
        var src=img.attr('src');
        var imgW=img.width(),imgH=img.height();
        $(document.body).append('<div class="preview" style="width:100%;height:100%;background:rgba(0,0,0,0.3);position:fixed;top:0;left:0;">\
                                       <div style="width:80%;height:90%;position:absolute;top:5%;left:10%;text-align: center;vertical-align: middle;"><span style="display: inline-block;height:100%;vertical-align: middle;"></span><img src="'+src+'" alt="" style="width:auto;display:inline-block;max-width:100%;max-height:100%;vertical-align: middle;"></div>\
                                   </div>')
    });
    $('body').delegate('.preview','click',function(){
        $(this).remove();
    });
    setTimeout(function(){
        $(window).scroll();
    },200);
});